<template>
  <div>
    <div class="detail-info" style="margin-top: 43px">
      <div class="form-item">
        <h4>基本信息</h4>
        <el-form label-width="180px">
          <el-row>
            <el-form-item label="所属设备">
              <span v-if="this.detailData.client === 0">全部</span>
              <span v-if="this.detailData.client === 10">PC订货</span>
              <span v-if="this.detailData.client === 20">惠配通</span>
              <span v-if="this.detailData.client === 30">惠付通</span>
            </el-form-item>
            <el-form-item label="所属分公司">
              <span>{{this.detailData.branchName}}</span>
            </el-form-item>
            <el-form-item label="所属部门">
              <span>{{this.detailData.departName}}</span>
            </el-form-item>
            <el-form-item label="所属仓库">
              <span v-if="this.detailData.limit_store_id === '0'">全部</span>
              <span v-if="this.detailData.limit_store_id !== '0'">{{this.detailData.limitStoreName}}</span>
            </el-form-item>
            <el-form-item label="客资类型">
              <span>{{this.detailData.customerName}}</span>
            </el-form-item>
            <!-- <el-form-item v-if="this.detailData.limit_user_type !== '1'" label="所属品牌">
              <span>{{this.detailData.brandName}}</span>
            </el-form-item>
            <el-form-item v-if="this.detailData.limit_user_type === '1'" label="商品类型">
              <span v-if="this.detailData.product_type === 10">常规</span>
              <span v-if="this.detailData.product_type === 40">冷链</span>
              <span v-if="this.detailData.product_type === 42">鲜食</span>
            </el-form-item> -->
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="detail-info" style="margin-top: 43px">
      <div class="form-item">
        <h4>活动信息</h4>
        <el-form label-width="180px">
          <el-form-item label="套餐名称">
            <span>{{this.detailData.promotion_name}}</span>
          </el-form-item>
          <el-form-item label="套餐起止时间">
            <span>{{this.detailData.start_time}} - {{this.detailData.end_time}}</span>
          </el-form-item>
          <!--<el-form-item label="可销售上线" v-if="this.detailData.limit_sell_count !== ''">-->
            <!--<span>{{this.detailData.limit_sell_count}}</span>-->
          <!--</el-form-item>-->
          <el-form-item label="起购金额" v-if="this.detailData.limit_satisfy_money !== ''">
            <span>{{this.detailData.limit_satisfy_money / 100}}</span>
          </el-form-item>
          <el-form-item label="限购条件">
            <span v-if="this.detailData.limit_buy_filter === '1'">每单</span>
            <span v-if="this.detailData.limit_buy_filter === '2'">全程</span>
            <span v-if="this.detailData.limit_buy_filter === '3'">不限</span>
          </el-form-item>
          <el-form-item label="限购数量">
            <span>{{this.detailData.limit_buy_count}}</span>
          </el-form-item>
          <el-form-item label="描述">
            <span>{{this.detailData.describe}}</span>
          </el-form-item>
          <el-form-item label="图片">
            <img :src="this.imgHost + '/' + this.detailData.cover_pic" class="avatar">
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="detail-info" style="margin-top: 43px">
      <div class="form-item">
        <h4>商品信息</h4>
        <el-table :data="this.detailData.product" border>
          <el-table-column label="商品类型" align="center" width="80px">
            <template scope="scope">
              <span v-if="Number(scope.row.is_master) === 1">主商品</span>
              <span v-if="Number(scope.row.is_master) === 0">副商品</span>
            </template>
          </el-table-column>
          <el-table-column prop="productid" label="商品ID" align="center" width="65px"></el-table-column>
          <el-table-column prop="name" label="商品名称" align="center" min-width="180px"></el-table-column>
          <el-table-column prop="saleunit" label="销售单位" align="center" width="80px"></el-table-column>
          <el-table-column prop="salenorm" label="销售规格" align="center" width="80px"></el-table-column>
          <el-table-column prop="saleprice" label="系统售价" align="center" width="80px"></el-table-column>
          <el-table-column prop="cgprice" label="最近一次采购价" align="center" width="120px"></el-table-column>
          <el-table-column prop="oldml" label="原毛利" align="center" width="70px"></el-table-column>
          <el-table-column prop="price_real" label="促销价" align="center"></el-table-column>
          <el-table-column prop="cxml" label="促销毛利" align="center" width="70"></el-table-column>
          <el-table-column label="促销毛利率" align="center" width="70">
            <template scope="scope">{{scope.row.cxmll}}%</template>
          </el-table-column>
          <el-table-column prop="cxmls" label="毛利损失" align="center" width="70"></el-table-column>
          <el-table-column prop="pnum" label="数量" align="center" width="70"></el-table-column>
          <el-table-column prop="cxName" label="促销费用" align="center" width="70"></el-table-column>
          <el-table-column prop="providerholdprice" label="供应商承担金额" align="center" width="70"></el-table-column>
        </el-table>
      </div>
    </div>
    <!-- <div class="detail-info" style="margin-top: 50px">
      <div class="form-item">
        <h4>套餐信息</h4>
          <el-table :data="comboInfo" border >
            <el-table-column label="套餐原价" prop="price_total" align="center"></el-table-column>
            <el-table-column label="套餐成本价" prop="cgprice" align="center"></el-table-column>
            <el-table-column label="套餐原毛利" prop="oldml" align="center"></el-table-column>
            <el-table-column label="套餐促销价" prop="price_real_total" align="center"></el-table-column>
            <el-table-column label="套餐促销毛利" prop="cxml" align="center"></el-table-column>
            <el-table-column label="套餐促销毛利率" prop="cxmll" align="center"></el-table-column>
            <el-table-column label="套餐毛利损失" prop="cxmlss" align="center"></el-table-column>
          </el-table>
      </div>
    </div> -->
    <div class="detail-info" style="margin-top: 43px;margin-bottom:80px">
      <div class="form-item">
        <h4>审核信息</h4>
        <el-table :data="this.detailData.checkInfo" border>
          <el-table-column prop="auditor" label="审核人名称" align="center"></el-table-column>
          <el-table-column prop="content" label="任务内容" align="center"></el-table-column>
          <el-table-column prop="resultName" label="审核结果" align="center"></el-table-column>
          <el-table-column prop="opinion" label="审核意见" align="center"></el-table-column>
          <el-table-column prop="auditTime" label="审核时间" align="center"></el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>
<script>
  import { activity } from '../../../../../config/proxy.js'
  import { apiHost } from '../../../../../config/settings.js'
  export default {
    data () {
      return {
        detailData: [],
        comboInfo: [],
        imgHost: ''
      }
    },
    methods: {
      searchDetail (id) {
        activity.sphd.detail({id: id}, (res) => {
          console.log(res)
          if (res.message === 'ok') {
            // this.detailData.product = JSON.parse(this.detailData.product)
            this.detailData = res.content
            this.imgHost = apiHost.imgHost
            var mainProduct = []
            var viceProduct = []
            this.forRes('main_product', 1, mainProduct)
            this.forRes('vice_product', 0, viceProduct)
            this.detailData.product = mainProduct.concat(viceProduct)
            // this.comboInfo[0] = {
            //   price_total: res.content.price_total, // 套餐原价
            //   cgprice: res.content.cgprice, // 套餐成本价
            //   oldml: res.content.oldml, // 套餐原毛利
            //   price_real_total: res.content.price_real_total, // 套餐促销价
            //   cxml: res.content.cxml, // 套餐促销毛利
            //   cxmll: res.content.cxmll, // 套餐促销毛利率
            //   cxmlss: res.content.cxmlss // 套餐促销毛利损失
            // }
            for (let index = 0; index < this.detailData.product.length; index++) {
              const element = this.detailData.product[index]
              element.saleprice = (element.saleprice / 100).toFixed(2)
              element.cgprice = (element.cgprice / 100).toFixed(2)
              element.oldml = (element.oldml / 100).toFixed(2)
              element.price_real = (element.price_real / 100).toFixed(2)
              element.cxml = (element.cxml / 100).toFixed(2)
              element.cxmls = (element.cxmls / 100).toFixed(2)
              element.providerholdprice = (element.providerholdprice / 100).toFixed(2)
            }
            console.log(this.detailData)
          } else {
            this.message('查看详情失败', 'error')
          }
        })
      },
      forRes (type, num, arr) {
        for (let index = 0; index < this.detailData[type].length; index++) {
          const element = this.detailData[type][index]
          element.is_master = num
          if (element.status === 1) {
            arr.push(element)
          }
        }
      },
      timeDeltSecond (d) { // 时间去秒
        if (d) {
          return d.split(' ')[0]
        }
      },
      message (text, type) { // 消息提示
        this.$message({
          showClose: true,
          message: text,
          type: type
        })
      }
    },
    created () {
      this.searchDetail(this.$store.state.tab.uid)
    }
  }
</script>
